package com.mkx.domain.entity;

import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import java.time.LocalDateTime;
import java.util.UUID;

/**
 * 用户实体
 * 聚合根：代表用户信息的核心实体
 */
@Getter
@Builder
public class User {
    
    /**
     * 用户ID
     */
    private final String id;
    
    /**
     * 用户名
     */
    private String username;
    
    /**
     * 密码（加密）
     */
    @Setter
    private String password;
    
    /**
     * 邮箱
     */
    private String email;
    
    /**
     * 手机号
     */
    private String phone;
    
    /**
     * 创建时间
     */
    private final LocalDateTime createdTime;
    
    /**
     * 更新时间
     */
    private LocalDateTime updatedTime;
    
    /**
     * 构造函数
     */
    public User(String id, String username, String password, String email, String phone, LocalDateTime createdTime, LocalDateTime updatedTime) {
        this.id = id != null ? id : UUID.randomUUID().toString();
        this.username = username;
        this.password = password;
        this.email = email;
        this.phone = phone;
        this.createdTime = createdTime != null ? createdTime : LocalDateTime.now();
        this.updatedTime = updatedTime != null ? updatedTime : LocalDateTime.now();
    }
    
    /**
     * 更新用户信息
     */
    public void updateInfo(String username, String email, String phone) {
        this.username = username;
        this.email = email;
        this.phone = phone;
        this.updatedTime = LocalDateTime.now();
    }
    
    /**
     * 更改密码
     */
    public void changePassword(String newPassword) {
        this.password = newPassword;
        this.updatedTime = LocalDateTime.now();
    }
}